/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.salary.db.impl;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.yunhoo.salary.model.SalaField;
import com.yunhoo.sys.db.util.IbatisTemplate;
import com.yunhoo.sys.util.common.LoginParam;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Administrator
 */
public class WageImpl {

    private static String NAME_SPACE = "wage.";
    private static String NAME_SPACE_REMOTE = "wage_u8.";

    private String getOrgCode() {
        return LoginParam.getOrg().getCode();
    }


    /*
     * 工资账套
     */
    public static String salaAcct(String acct) {
        Map map = new HashMap();
        map.put("orgCode",LoginParam.getOrg().getCode());
        map.put("acct",acct);
        return (String) IbatisTemplate.query(NAME_SPACE + "salaAcct", map);
    }

    /*
     * 工资账套年度列表
     */
    public static List<Integer> salaYears(Map map) {
        map.put("orgCode",LoginParam.getOrg().getCode());
        return IbatisTemplate.queryForList(NAME_SPACE + "salaYears", map);
    }

    public static List<Integer> iyearList(Map map) {
        return IbatisTemplate.queryForList(NAME_SPACE + "iyearList", map);
    }

    public static List<HashMap<String, String>> wageItems(Map map) {
        return (List<HashMap<String, String>>) IbatisTemplate.queryForList(NAME_SPACE + "wageItemsList", map);
    }

    public static List salaItems(Map map) {
        return IbatisTemplate.queryForList(NAME_SPACE + "salaItemsList", map);
    }

    public static List salaByPerson(Map map) {
        return IbatisTemplate.queryForList(NAME_SPACE + "salaInfo", map);
    }

    //个人月份工资以Map格式返回
    public static List<Map> monthPsnWage(Map map) {
        return IbatisTemplate.queryForList(NAME_SPACE + "monthPsnWage", map);
    }

    public static List<Map> psnWageLedger(Map map) {//个人年度工资台账，查询结果集为Map
        return IbatisTemplate.queryForList(NAME_SPACE + "psnWageLedger", map);
    }

    public static List psnSalaLedger(Map map) {
        return IbatisTemplate.queryForList(NAME_SPACE + "psnSalaLedger", map);
    }

    public static List salaSumByYear(Map map) {
        return IbatisTemplate.queryForList(NAME_SPACE + "salaSumByYear", map);
    }

    public static List<Map> wageSumByYear(Map map) {
        return IbatisTemplate.queryForList(NAME_SPACE + "wageSumByYear", map);
    }

    public static List<SalaField> salaFields(Map map) {
        return IbatisTemplate.queryForList(NAME_SPACE + "salaFields", map);
    }

    public static List<Integer> monthList(String year) {
        Map map = new HashMap();
        map.put("orgCode", LoginParam.getOrg().getCode());
        map.put("year", year);
        return IbatisTemplate.queryForList(NAME_SPACE + "monthList", map);
    }

    public static void importFromRemoteServer(Map map) throws SQLException {
        SqlMapClient client = IbatisTemplate.getSqlMapClient();
        client.insert(NAME_SPACE_REMOTE + "importFromRemoteServer_old", map);
    }

    public static void deleteData(Map map) {
        IbatisTemplate.delete(NAME_SPACE + "deleteData", map);
    }

    public static List<ArrayList> psnSala(Map map) {
        return IbatisTemplate.queryForList(NAME_SPACE + "psnSala", map);
    }

    public static List<HashMap> test(Map map) {
        return IbatisTemplate.queryForList(NAME_SPACE + "test", map);
    }

    public final static void main(String[] args) {
        try {
            Map map = new HashMap();
            map.put("cpsn_number", "01003");
            map.put("iyear", 2011);
            map.put("imonth", 1);
            List<HashMap> sala = test(map);
            System.out.println("Size:" + sala.size() + sala);
//            for(ArrayList fields:sala){
//                for(Object field:fields)
//                    System.out.print(field.toString() + ",");
//                System.out.println();
//            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
